<template>
    <div class="order-report">
        <div class="report-table-top-title">通知管理</div>
        <div class="report-table-form1">
            <el-form
                ref="form"
                size="small"
                inline
                :model="form"
                label-width="80px"
            >
                <el-form-item label="标题:" prop="title">
                    <el-input
                        type="text"
                        v-model="form.title"
                        class="items"
                    ></el-input>
                </el-form-item>
                <el-form-item label="系统:" prop="plantform">
                      <el-select
                        class="items"
                        v-model="form.plantform"
                        placeholder="请选择代理商"
                        size="small"
                    >
                        <el-option label="全部" value></el-option>
                        <el-option
                            v-for="item in systemList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                        ></el-option>
                    </el-select>
                    <el-button
                        type="primary"
                        size="small"
                        @click.stop="
                            position = 1
                            getList()
                        "
                        >查询</el-button
                    >
                    <el-button
                        type="primary"
                        size="small"
                        @click.stop="
                            showSet = true
                            currRow = {}
                        "
                        >新增</el-button
                    >
                </el-form-item>
            </el-form>
        </div>
        <div class="page-padding-gray-small"></div>
        <div class="report-table-wrapper">
            <el-table
                :header-cell-style="headerCellStyle"
                size="small"
                :data="tabData"
                border
                style="width: 100%"
            >
                <el-table-column
                    prop="title"
                    label="标题"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="plantformDes"
                    label="系统"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column
                    prop="roleIdDec"
                    label="角色"
                    min-width="160"
                    show-overflow-tooltip
                ></el-table-column>
                <el-table-column fixed="right" label="操作" width="150px">
                    <template slot-scope="scope">
                        <el-button
                            size="mini"
                            type="primary"
                            @click="toDetail(scope.row)"
                            >修改</el-button
                        >
                        <el-button
                            size="mini"
                            type="danger"
                            @click="delRow(scope.row)"
                            >删除</el-button
                        >
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 分页 -->
        <div class="report-table-block">
            <div class="report-table-block-in">
                <el-pagination
                    background
                    :current-page.sync="currentPage"
                    @current-change="handleCurrentChange"
                    :page-size="pageSize"
                    layout="prev, pager, next, total"
                    :total="totalNum"
                ></el-pagination>
            </div>
        </div>
        <setNotice
            :value.sync="showSet"
            :currRow="currRow"
            :systemList='systemList'
            :roleList='roleList'
            @getList="getList"
        ></setNotice>
    </div>
</template>

<script type="text/ecmascript-6">
import setNotice from './components/setNotice'
export default {
    components: {
        setNotice
    },
    data: function () {
        return {
            showSet: false,
            currRow: {},
            roleList: [], // 状态列表
            systemList: [], // 状态列表
            form: {
                title: '',
                plantform: ''
            },
            currentPage: 1,
            pageSize: 10,
            totalNum: 0,
            tabData: []
        }
    },
    mounted () {
    },
    created () {
        this.getList()
        this.getRoleList()
        this.getSystemList()
    },
    methods: {
        toDetail (item) {
            this.showSet = true
            this.currRow = item
        },
        getRoleList () {
            this.$http.get(this.$store.state.IP + '/notify/announce/roleList', {
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                console.log('-------------------------------------------')
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    this.roleList = response.data
                }
            }, response => {
            })
        },
        getSystemList () {
            this.$http.get(this.$store.state.IP + '/notify/announce/systemList', {
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                response = response.body
                console.log(response)
                if (response.ret === '0') {
                    this.systemList = response.data
                }
            })
        },
        delRow (row) {
            console.log(row)
            this.$confirm('确定删除吗?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                let params = {
                    params: {
                    }
                }
                this.$http.get(this.$store.state.IP + '/notify/announce/delete?id=' + row.id, params).then(response => {
                    response = response.body
                    console.log(response)
                    if (response.ret === '0') {
                        this.$message({
                            message: '删除成功',
                            type: 'success'
                        })
                        this.getList()
                    }
                }, response => {
                    console.log('调用添加失败')
                })
            }).catch(() => {
            })
        },
        handleCurrentChange (page) {
            // 换页
            this.currentPage = page
            this.getList()
        },
        getList () {
            // 获取 所有 服务列表
            this.$http.post(this.$store.state.IP + '/notify/announce/list', {
                page: this.currentPage - 1,
                size: this.pageSize,
                ...this.form
            },
                {
                    'emulateJSON': false
                }
            ).then(response => {
                response = response.body
                this.tabData = []
                if (response.ret === '0') {
                    this.tabData = response.data.list
                    this.totalNum = response.data.total
                }
            }, response => {
            })
        }
    }
}
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
.el-dropdown-link
    color: #409EFF
    cursor: pointer

.order-report
    width: 100%
    background: #fff
    min-height: calc(100vh - 65px)
    position: relative

    .report-table-top-title
        width: 100%
        height: 64px
        line-height: 64px
        color: #000
        font-size: 18px
        background: #f1f0f5

    .report-table-form1
        width: 100%
        min-height: 40px
        padding: 16px 0 0 22px
        box-sizing: border-box
        background: #fff
        overflow: hidden

        .report-table-form1-line
            min-height: 32px
            margin-bottom: 16px

            .report-table-form1-item
                display: inline-block
                vertical-align: top
                height: 32px
                margin-right: 15px
                line-height: 32px

                &.word
                    margin-right: 0

                &.samll
                    font-size: 15px
                    text-align: left

                &.big
                    margin-right: 100px

    .report-table-block
        width: 100%
        padding-top: 22px
        height: 80px
        background: #fff
        box-sizing: border-box

        .report-table-block-in
            float: right
            padding-right: 17px

    .page-padding-gray-small
        width: 100%
        height: 22px
        background: #f1f0f5

    .page-padding
        width: 100%
        height: 20px
        background: #fff

    .report-table-total
        width: 100%
        font-size: 16px
        color: #409EFF
        padding: 22px
        margin-top: 22px
        box-sizing: border-box
        background: #fff

    .page-all-loading
        position: fixed
        top: 55%
        left: 40%
        width: 200px

.title
    display: inline-block
    min-width: 120px
    text-align: right
    font-weight: bold
    line-height: 35px

.value
    display: inline-block
    line-height: 35px
    min-width: 150px

.items
    width: 200px

.item
    margin-bottom: 0px
</style>

